<template lang="html">
  <div class="productdetails">
    <Header :HeaderTitle="header_title"></Header>
     <!-- 轮播图 -->
    <carousel :listshuju="img_list"></carousel>
    <Details v-bind:detailsimg="goods" v-on:listenToChildEvent="showMsgFromChild"></Details>
    <ul class="purchase_box">
      <li class="purchase_main">总价：{{zongjianum}}</li>
      <li class="purchase_at"><router-link :to="{path:'/orderform',query:{id:goodsid,numer:num}}">立即购买</router-link></li>
    </ul>
  </div>
</template>

<script type="text/javascript">
import Header from "../header/header.vue";
import carousel from "../Carousel/Carousel.vue";
import details from "../goodsdetails/name.vue";
export default {
  name: 'cuxiao',
  data(){
  	return{
  		header_title:{url:"/",title:"商品详情"},
      goods:{},
      img_list:[],
      num:1,
      cur_id:"",
      sign:"",
      goodsid:'',
      zongjianum:"0"
  	}
  },
  created:function(){
    let cur_id = sessionStorage.getItem("cur_id"),
    sign = sessionStorage.getItem("sign"),
    qs = require('querystring'),
    routerParams = this.$route.query.id,
    conent = this;
      if (!cur_id||!sign) {
        sessionStorage.clear();
        top.location = "index.html";
      };
      let _url = "/index.php?g=app&m=shopping&a=putonggoods_one_post";
      let _data = {
        id:routerParams
      }
      conent.cur_id = cur_id;
      conent.sign = sign;
      conent.goodsid = routerParams;
      conent.$http.post(_url,_data).then(function(data){
          if(data.data.status== "1"){
            conent.goods=data.data.data.putonggoods_info;
            conent.img_list=data.data.data.putonggoods_info.img_list.split(",");
            conent.zongjianum=parseInt(data.data.data.putonggoods_info.freight)+parseInt(data.data.data.putonggoods_info.price);
          }else {
            
          }
      },function(response){
          conent.$toast(response);
      })
  },
  methods:{
    showMsgFromChild:function(data){
      this.num = data;
      this.zongjianum=parseInt(this.goods.freight)+parseInt(this.goods.price)*this.num;
    },
    putonggoodsbuy:function(){
      let _url = '/index.php?g=app&m=shopping&a=putonggoods_buy_post',
      qs = require('querystring'),
      conent = this,
      _data={
        cur_id:conent.cur_id,
        sign:conent.sign,
        num:conent.num,
        id:conent.goodsid
      }
      conent.$http.post(_url,qs.stringify(_data)).then(function(data){
          if(data.data.status== "1"){
            conent.$router.push({ path: '/orderform', params: { userId: "wise" }})
          }else {
            conent.$toast(data.data.info);
            if(data.data.info =="登录过期，请重新登录"){
              sessionStorage.clear();
              top.location = "index.html";
            }
          }
      },function(response){
          conent.$toast(response);
      })
    }
  },
  components:{
  	'Header':Header,
  	'carousel':carousel,
  	'Details':details
  }
}
</script>

<style scoped lang="less">
@import '../../../assets/less/index.less';
.productdetails{
  .purchase_box{
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100vw;
    height: 13.33vw;
    font-size:@h1_font_size;
    color: @color1;
    li{height: 100%;float: left;line-height: 13.33vw;}
    .purchase_main{
      width: 66.6%;
      background-color: @color6;
    }
    .purchase_at{
      width: 33.33%;
      background-color: @color;
      a{
        color: @color1;
        display: inline-block;
        width: 100%;
        height: 100%;
      }
    }
  }
}
</style>